<?php 
	require_once("example_form.php");
	$error = NULL;
	$success = NULL;
	$form = new ExampleForm();
	if($_POST){
		$form->populate($_POST);
		if($form->isValid()){
			$data = $form->getData();
			// Save data
			var_export($data);
			$success = "Saved successfully.";
		} else {
			$error = "Please, fill in the fields marked in red.";
		}
	}
?>
<!doctype html>
<html lang="pt-br">
	<head>
		<meta charset="utf-8" />
		<title>Example Form</title>
		<style type="text/css">
			form div{margin:5px 0; padding:5px;}
			form div label{display:block;}
			input[type=text], textarea, select{width:250px;}
			p.error { background: #faafba; border:1px solid #d00; padding:5px;}
			p.success { background: #affaba; border:1px solid #0d0; padding:5px;}
			.field-with-error{ color:red; }
		</style>
	</head>
	<body>
		<h1>Example Form</h1>
		<?php if (NULL != $error): ?>
			<p class="error"><?php echo $error ?></p>
		<?php endif ?>
		<?php if (NULL != $success): ?>
			<p class="success"><?php echo $success ?></p>
		<?php endif ?>
		<?php echo $form->open() ?>
			<div>
				<?php echo $form->label("name") ?>
				<?php echo $form->render("name") ?>
			</div>
			<div>
				<?php echo $form->label("gender") ?>
				<?php echo $form->render("gender") ?>
			</div>
			<div>
				<?php echo $form->label("age") ?>
				<?php echo $form->render("age") ?>
			</div>
			<div>
				<?php echo $form->label("description") ?>
				<?php echo $form->render("description") ?>
			</div>
			<div>
				<?php echo $form->label("published") ?>
				<?php echo $form->render("published") ?>
			</div>
			<div>
				<?php echo $form->submit() ?>
			</div>
		<?php echo $form->close() ?>
	</body>
</html>